import java.lang.reflect.Array;
import java.util.Arrays;

public class Sort {

    public static void insertSort(int[] array){
        for (int i = 1; i < array.length; i++) {
            int tmp = array[i];
            int j = i-1;
            while (j >= 0 && array[j] > tmp){
                array[j+1] = array[j];
                j--;
            }
            array[j+1] = tmp;
        }
    }

    public static void shellSort(int[] array){
       int gap = array.length;
       while (gap > 1){
           gap /= 2;
           shell(array,gap);
       }
    }
    public static void shell(int[] array,int gap){
        for (int i = gap; i < array.length; i++) {
            int tmp = array[i];
            int j = i-gap;
            while (j >= 0 && array[j] > tmp){
                array[j+gap] = array[j];
                j -= gap;
            }
            array[j+gap] = tmp;
        }
    }


    public static void selectSort(int[] array){
        for (int i = 0; i < array.length; i++) {
            int mixIndex = i;
            int j = i+1;
            for (; j < array.length; j++) {
                if (array[j] < array[mixIndex]){
                    mixIndex = j;
                }
            }
            swap(array,mixIndex,i);
        }

    }

    public static void swap(int[] array,int i , int j){
        int tmp = array[i];
        array[i] = array[j];
        array[j] = tmp;
    }


    public static void main(String[] args) {
        int arr[] =  {3, 2, 4, 1, 5, 6};
        //insertSort(arr);
        //shellSort(arr);
        selectSort(arr);
        System.out.println(Arrays.toString(arr));
    }






}
